public class Solution {
   static class ListNode{
        public int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode partition(ListNode pHead, int x) {
        if(pHead==null) return null;
        ListNode headA=null;
        ListNode cur1=headA;
        ListNode headB=null;
        ListNode cur2=headB;

        while(pHead!=null){
            if(pHead.val<x){
                cur1.next=pHead;
                cur1=cur1.next;
            }else{
                cur2.next=pHead;
                cur2=cur2.next;
            }
            pHead=pHead.next;
        }
        cur1.next=headB.next;
        return headA.next;
    }
}
